{extend name="public:layout" /}
{block name="title"}添加表单{/block}
{block name="head"}
{:widget('common/Form/icheckRes')}
{:widget('common/Form/validRes')}
{/block}
{block name="body"}
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox">
        <div class="ibox-title">
            <ol class="breadcrumb">
                <li><i class="fa fa-hand-o-right"></i> <a href="{:url('Form/index')}"> 表单列表</a></li>
                <li><a href="{:url('index',['form_id'=>$Request.param.form_id])}"> 表单字段列表</a></li>
                <li class="active">添加表单字段</li>
            </ol>
        </div>
        <div class="ibox-content">
            <form method="post" class="form-horizontal" id="form">
                <div class="form-group">
                    <label class="col-sm-2 control-label">字段标题</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control" placeholder="请输入字段标题"
                               name="field_title" datatype="*"
                               nullmsg="请输入字段标题！" errormsg=""/>
                    </div>
                    <label class="col-sm-2 control-label">字段名</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control"
                               name="field_name" datatype="*"
                               nullmsg="请输入字段名！" errormsg=""/>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">字段类型</label>
                    <div class="col-sm-4">
                        <select name="field_type" id="fieldType" class="form-control">
                            <option value="input">单行文本</option>
                            <option value="box">选项</option>
                            <option value="number">数字框</option>
                            <option value="textarea">多行文本</option>
                        </select>
                    </div>
                    <label class="col-sm-2 control-label">提示信息</label>
                    <div class="col-sm-4">
                        <input type="text" class="form-control"
                               name="field_tips" />
                    </div>
                </div>
                <div id="fieldTpl">

                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label Validform_label">验证规则</label>
                    <div class="col-sm-10">
                        {foreach $validRule as $key=>$value}
                        <label class="checkbox-inline i-checks">
                            <input type="checkbox" name="validate[]" value="{$key}" /> {$value}
                        </label>
                        {/foreach}
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-sm-2 control-label">排序</label>

                    <div class="col-sm-2">
                        <input type="text" class="form-control" placeholder="请输入排序"
                               name="field_sort" value="0" datatype="*"
                               nullmsg="请输入排序！" errormsg=""/>
                    </div>
                </div>
                <div class="form-group">
                    <div class="col-sm-10 col-sm-offset-2">
                        <button class="btn btn-primary"
                                onclick="ajaxSubForm();" type="submit">
                            保存内容
                        </button>
                        <a href="{:url('index',['form_id'=>$Request.param.form_id])}" class="btn btn-white">取消</a>
                        <span id="validError"></span>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
{/block}
{block name="script"}
<script type="text/javascript">
    $(function () {
        iCheck();
        $("#fieldType").change(function () {
            var fieldType = $(this).val();
            $.ajax({
                url: '{:url("getFieldTpl")}',
                type: "POST",
                data: {
                    action: 'add',
                    fieldType: fieldType
                },
                success: function (data) {
                    $("#fieldTpl").html(data);
                    iCheck();
                }
            })
        });
        $("#fieldType").trigger("change"); //加载触发
    })
</script>
{/block}